import { Component, ComponentType } from "react";
import CounterContext from "../contexts/counter";

export default function withContext(WrappedComponent: ComponentType) {
  return class WithContextComponent extends Component {
    render() {
      return (
        <CounterContext.Consumer>
          {(value) => <WrappedComponent {...this.props} extra={value} />}
        </CounterContext.Consumer>
      );
    }
  };
}
